package com.mayee.me.gateway.route;

import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: mayee
 * @create: 2020-12-28 21:36
 **/
@Data
public class PredicateEntity  implements Serializable {
    private static final long serialVersionUID = 8674937684954114770L;
    private String name;
    private Set<String> values = new HashSet<>();
    private static final List<String> WHEN = Arrays.asList("After", "Before", "Between", "Cookie", "Header", "Host", "Method", "Path", "Query", "RemoteAddr");

    public void setName(String name) {
        if (WHEN.contains(name)) {
            this.name = name;
        }
    }

    /*
        这里的 toString 方法不要随便改格式，否则会出现找不到路由的情况
    */
    @Override
    public String toString(){
        return String.format("%s = %s", this.name, String.join(",", this.values));
    }
}